#!/usr/bin/perl
use lib '/data1/bsi/bioinf_int/s106381.borawork/data_HTHGU/parse_cdf';


use Bio::Affymetrix::WCEL;
#use strict;
my $cel_template=new Bio::Affymetrix::WCEL;
my $cel_ht=new Bio::Affymetrix::WCEL;

open FIN,"output.txt";
my $l="";
my %MAP={};
while($l=<FIN>) {
    chomp $l;
    $l =~ s/[\r,\l,\n]+$//g;
    my @line = split(/\t/,$l);
    my $xht=$line[$#line-3];
    my $yht=$line[$#line-2];
    my $xu133=$line[$#line-1];
    my $yu133=$line[$#line];
    my @xy=($xht,$yht);
    $MAP{$xu133 . "-" . $yu133} = \@xy;
}
close FIN;

$cel_template->parse_from_file("GSM245730.CEL");

$cel_ht->parse_from_file("foo.CEL");

my $im = $cel_template->intensity_map();
my $imht =$cel_ht->intensity_map();

# Print out all of the intensities for each square

for (my $x=0;$x<scalar(@{$cel_template->intensity_map()});$x++) {
        for (my $y=0;$y<scalar(@{$cel_template->intensity_map()->[$x]});$y++) {
	    my $key = $x . "-" . $y;
	    if(exists $MAP{$key}) {
		my $xy_ref = $MAP{$key};
		my $xht = $xy_ref->[0];
		my $yht = $xy_ref->[1];
                $im->[$x][$y]->[0] =  $imht->[$xht][$yht]->[0] ;
                $im->[$x][$y]->[1] =  $imht->[$xht][$yht]->[1] ;
                $im->[$x][$y]->[2] =  $imht->[$xht][$yht]->[2] ;
	    }
        }
}

$cel_template->write_to_file("foo_u133a.cel");
